Skip to content

Conversation

@georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Dec 19, 2025

Explanation

Problem:
The RampsController needs to determine whether a user's region is eligible for ramps (on/off-ramp services). This requires fetching eligibility information from the regions API and making it available to consumers.

Solution:
This PR adds region eligibility support to the RampsController:

  1. New Eligibility type - Defines eligibility information returned from /regions/countries/{isoCode} endpoint with aggregator, deposit, and global flags indicating what services are available for a region.

  2. New getEligibility service method - Calls /regions/countries/{isoCode} to fetch eligibility for a specific region (e.g., fr, us-ny). The ISO code is normalized to lowercase.

  3. Automatic eligibility fetching - updateGeolocation() now automatically fetches and stores eligibility in controller state after successfully getting geolocation. This ensures eligibility is always up-to-date with the user's current location.

  4. New getCountries controller method - Fetches the list of supported countries from /regions/countries and filters them using OnRampSDK aggregator logic:

    • For buy: filters by country.supported
    • For sell: filters by country.supported OR if any state has supported !== false
  5. Eligibility in controller state - Eligibility is stored as a persisted property in RampsControllerState, making it accessible to consumers via controller.state.eligibility.

Notable implementation details:

  • Eligibility is automatically fetched when geolocation is updated, keeping them in sync
  • The eligibility endpoint supports both country codes (fr) and state codes (us-ny)
  • getCountries uses OnRampSDK's aggregator filtering logic for consistency with existing SDK behavior
  • Both geolocation and eligibility are persisted in controller state

References

  • TRAM-2923

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Introduces region eligibility support and country listing with caching, and auto-syncs eligibility with geolocation.

  • Adds eligibility to RampsController state (persisted/visible) and updateEligibility(isoCode) with normalized caching; prevents stale overwrites and clears on failures
  • updateGeolocation() now automatically fetches eligibility and retains request caching/TTL semantics
  • Adds getCountries(action) to controller with cached responses
  • Expands RampsService: new getCountries (regions cache URLs, support filtering), getEligibility(isoCode), shared request helper adding sdk/controller/context params; introduces RampsApiService, RAMPS_SDK_VERSION, and context option
  • Updates messenger action types/permissions and public exports; enables resolveJsonModule to read package.json version
  • Comprehensive tests added/updated and changelog entry for eligibility state

Written by Cursor Bugbot for commit 18dd92b. This will update automatically on new commits. Configure here.

@georgeweiler georgeweiler changed the title feat(ramps-controller): adds ramps controller methods for region elig… feat(ramps): adds controller methods for region eligibility Dec 19, 2025
@georgeweiler georgeweiler marked this pull request as ready for review January 6, 2026 03:21
@georgeweiler georgeweiler requested review from a team as code owners January 6, 2026 03:21
@georgeweiler
Copy link
Contributor Author

cursor review

@georgeweiler
Copy link
Contributor Author

cursor review

@georgeweiler
Copy link
Contributor Author

cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!

pkowalski
pkowalski previously approved these changes Jan 7, 2026
Comment on lines 467 to 478
if (action === 'buy') {
return country.supported;
}

if (country.states && country.states.length > 0) {
const hasSupportedState = country.states.some(
(state) => state.supported !== false,
);
return country.supported || hasSupportedState;
}

return country.supported;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding early return for action buy and not check for the states in line 467-469: I would expect this early return only if no states are there.

why are we early returning the value for buy?

}

return country.supported;
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCountries filtering ignores action parameter for buy/sell differentiation

Medium Severity

The getCountries method applies the same filtering logic for both 'buy' and 'sell' actions, but according to the PR description, the behavior should differ: for 'buy', filtering should only use country.supported, while for 'sell', it should include countries where country.supported is true OR any state has supported !== false. The current implementation applies the country.supported || hasSupportedState logic regardless of the action parameter. The action variable is passed to the API request but is never used in the filter condition, causing 'buy' to incorrectly include countries that only have supported states but where the country itself is unsupported.

Fix in Cursor Fix in Web

@georgeweiler georgeweiler added this pull request to the merge queue Jan 7, 2026
Merged via the queue into main with commit 2dffa10 Jan 7, 2026
286 checks passed
@georgeweiler georgeweiler deleted the TRAM-2923-ramps-controller-get-eligibility branch January 7, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants